package com.zhijiaoyun.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhijiaoyun.common.DsConstant;
import com.zhijiaoyun.dao.ITeacherDao;
import com.zhijiaoyun.model.Teacher;
import com.zhijiaoyun.model.dto.PageData;
import com.zhijiaoyun.model.dto.PageList;
import com.zhijiaoyun.service.ITeacherService;

/**
 * @author shisfish
 * @date 2017/6/6
 */
@Service(value = "teacherService")
public class TeacherServiceImpl implements ITeacherService {

	@Resource 
	ITeacherDao teacherDao;
	
	@Override
	public void addTeacher(Teacher teacher) {
		teacherDao.insert(teacher);
	}

	@Override
	public Teacher getTeacherByTeacherId(Long teacherId) {
		return teacherDao.selectByPrimaryKey(teacherId);
	}

	@Override
	public void updateTeacher(Teacher teacher) {
		teacherDao.updateByPrimaryKey(teacher);
	}

	@Override
	public PageList<Teacher> pageByParams(int pageIndex, int pageSize, String name) {
		int count = teacherDao.countByParams(name);
		PageData pageData;
		List<Teacher> list;
		PageList<Teacher> pageList = new PageList<>();
		if (count > 0) {
			pageData = PageData.createPage(count, pageIndex, pageSize);
			list = teacherDao.pageByParams(pageData.getBeginIndex(), pageData.getPageSize(), name);
			pageList = new PageList<>(list, pageData);
		}
		return pageList;
	}

	@Override
	public List<Teacher> getTeacherByNameF(String name) {
		return teacherDao.selectByNameF(DsConstant.LIMIT_PAGE_SIZE, name);
	}

	@Override
	public List<Teacher> listByIds(List<String> teacherIds) {
		return teacherDao.listByIds(teacherIds);
	}

}
